package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LeaveRetireUser;
import com.ruoyi.system.service.ILeaveRetireUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 离退人员Controller
 * 
 * @author ruoyi
 * @date 2023-12-16
 */
@RestController
@RequestMapping("/system/retireUser")
public class LeaveRetireUserController extends BaseController
{
    @Autowired
    private ILeaveRetireUserService leaveRetireUserService;

    /**
     * 查询离退人员列表
     */
    @PreAuthorize("@ss.hasPermi('system:retireUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(LeaveRetireUser leaveRetireUser)
    {
        startPage();
        List<LeaveRetireUser> list = leaveRetireUserService.selectLeaveRetireUserList(leaveRetireUser);
        return getDataTable(list);
    }

    /**
     * 导出离退人员列表
     */
    @PreAuthorize("@ss.hasPermi('system:retireUser:export')")
    @Log(title = "离退人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LeaveRetireUser leaveRetireUser)
    {
        List<LeaveRetireUser> list = leaveRetireUserService.selectLeaveRetireUserList(leaveRetireUser);
        ExcelUtil<LeaveRetireUser> util = new ExcelUtil<LeaveRetireUser>(LeaveRetireUser.class);
        util.exportExcel(response, list, "离退人员数据");
    }

    /**
     * 获取离退人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:retireUser:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(leaveRetireUserService.selectLeaveRetireUserByUserId(userId));
    }

    /**
     * 新增离退人员
     */
    @PreAuthorize("@ss.hasPermi('system:retireUser:add')")
    @Log(title = "离退人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LeaveRetireUser leaveRetireUser)
    {
        return toAjax(leaveRetireUserService.insertLeaveRetireUser(leaveRetireUser));
    }

    /**
     * 修改离退人员
     */
    @PreAuthorize("@ss.hasPermi('system:retireUser:edit')")
    @Log(title = "离退人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LeaveRetireUser leaveRetireUser)
    {
        return toAjax(leaveRetireUserService.updateLeaveRetireUser(leaveRetireUser));
    }

    /**
     * 删除离退人员
     */
    @PreAuthorize("@ss.hasPermi('system:retireUser:remove')")
    @Log(title = "离退人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(leaveRetireUserService.deleteLeaveRetireUserByUserIds(userIds));
    }
}
